package site.xuxingcan;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Created by xuxingcan on 16-6-27.
 */
public class SocketHelper {
    PrintWriter os;
    BufferedReader is;

    public SocketHelper(Socket socket) throws IOException {
        os = new PrintWriter(socket.getOutputStream());
        is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    }

    public void writeLineAndFlush(String s) {
        if (!s.endsWith("\n")) {
            s = s + "\n";
        }
        os.write(s);
        os.flush();
    }

    public String readLine() throws IOException {
        return is.readLine();
    }
}